每天早上 08:00 自動抓取 Google Calendar 當日事件 → 格式化成提醒文字 → 根據條件發送 Email 或 Line Notify → 將傳送結果記錄(選擇性:Notion/Google Sheets)。
flowchart TD
A[Cron 排程 08:00] --> B[Google Calendar Node: Get Events]
B --> C[Function: 篩選 & 格式化訊息]
C --> D{If: 有無行程?}
D -- True --> E[Email Node: 寄出提醒]
D -- True --> F[Line Notify: 傳送提醒]
D -- False --> G[Optional: 寄「今日無行程」或不動作]
E --> H[Record: Notion/Google Sheets 儲存紀錄]
F --> H
H --> I[End]
Cron Node
→ Type: At Date/Time / Daily → Time: 08:00
。Credential:Google Calendar OAuth2(已建立)
Operation:Get All Events
或 Get Events
重要參數(n8n expression 範例):
Time Min
:={{ $moment().startOf('day').toISOString() }}
Time Max
:={{ $moment().endOf('day').toISOString() }}
maxResults
、orderBy
:startTime
輸出重點:每個 event 應包含 summary
(標題)、start.dateTime
或 start.date
、end.dateTime
、description
、location
。
hasEvents
與 message
。// 假設 Google Calendar 節點輸出 items[0].json.items
const events = items[0].json.items || [];
if (!events.length) {
return [{ json: { hasEvents: false, message: "今天沒有行程 🎉" } }];
}
let msg = "📅 今日行程提醒:\n\n";
events.forEach(ev => {
const start = ev.start?.dateTime || ev.start?.date || "時間未定";
const title = ev.summary || "無標題行程";
msg += `• ${title} — ${start}\n`;
if (ev.description) msg += ` 備註: ${ev.description}\n`;
});
return [{ json: { hasEvents: true, message: msg } }];
{{$json["hasEvents"]}}
is trueCredential:SMTP (Gmail / App Password) 或 Gmail OAuth
欄位範例:
={{"【Daily】今日行程提醒:" + $moment().format('YYYY-MM-DD')}}
={{ $json["message"] }}
若想寄 HTML,可用 <br>
格式化。
取得個人或群組 Token(https://notify-bot.line.me/my/)
用 n8n 的 HTTP Request 節點:
Method: POST
URL: https://notify-api.line.me/api/notify
Headers:
Authorization: Bearer YOUR_LINE_TOKEN
Content-Type: application/x-www-form-urlencoded
Body (form-urlencoded): message={{ $json["message"] }}
created
時間和今天的時間策略。